package com.cxg.fairy.ec.detail;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.cxg.fairy.ui.recycler.MultipleItemEntity;
import com.cxg.fairy.util.toasty.Toasty;
import com.diabin.latte.ec.R;
import com.hedgehog.ratingbar.RatingBar;

import java.util.List;

/**
 * Created by Administrator on 2018/4/10.
 */

public class CommentListAdapter extends ArrayAdapter{


    public CommentListAdapter(@NonNull Context context, int resource, @NonNull List objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        MultipleItemEntity entity = (MultipleItemEntity) getItem(position);
        final String username = entity.getField("name");
        final String headIco = entity.getField("headIco");
        final int RatingBar = entity.getField("RatingBar");
        final String eval = entity.getField("eval");
        final String time = entity.getField("time");
        LinearLayoutCompat view = (LinearLayoutCompat) LayoutInflater.from(parent.getRootView().getContext()).inflate(R.layout.item_goods_detail_comment, parent,false);
        RatingBar mRatingBar = (RatingBar) view.findViewById(R.id.rst_comment_start);
        mRatingBar.setStar(RatingBar/2);
        AppCompatTextView mTextUserName = (AppCompatTextView) view.findViewById(R.id.atv_comment_user_name);
        AppCompatTextView mContent = (AppCompatTextView) view.findViewById(R.id.atv_comment_content);
        AppCompatTextView mTime =(AppCompatTextView) view.findViewById(R.id.atv_comment_time);

        mTextUserName.setText(username);
        mContent.setText(eval);
        mTime.setText(time);

        //星级评定交互
        mRatingBar.setOnRatingChangeListener(
                new RatingBar.OnRatingChangeListener() {
                    @Override
                    public void onRatingChange(float RatingCount) {
                        Toasty.normal(getContext(), "the fill star is" + RatingCount).show(); 
                    }
                }
        );

        return view;
    }
}
